package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.AliyunOSSOperators;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/upload")
public class UploadController {
    @Autowired
    private AliyunOSSOperators aliyunOSSOperators;

    @PostMapping
    public Result upload(MultipartFile file) throws Exception {
        if (file != null){
            String upload = aliyunOSSOperators.upload(file.getBytes(), file.getOriginalFilename());
            return Result.success(upload);
        }
        return Result.error("上传失败");
    }
}
